<template>
	<transition name="el-zoom-in-center">
		<div class="JNPF-preview-main">
			<div class="JNPF-common-page-header">
				<el-page-header @back="goBack" :content="!dataForm.id ? '新建' : isDetail ? '详情' : '编辑'"/>
				<div class="options">
					<el-button type="primary" @click="dataFormSubmit()" v-if="!isDetail">确 定</el-button>
					<el-button @click="goBack">取 消</el-button>
				</div>
			</div>
			<el-row :gutter="15"  class="main" :style="{margin: '0 auto',width:'100%'}">
			<el-form ref="elForm" :model="dataForm" size="medium" label-width="130px" label-position="right" :disabled="!!isDetail" :rules="rules">
				<el-col :span="12">
					<el-form-item label="安全制度名称" prop="aqzdmc"  >
						<el-input v-model="dataForm.aqzdmc" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="发布部门" prop="fbbm"  >
						<el-select filterable v-model="dataForm.fbbm" placeholder="请选择" clearable :style='{"width":"100%"}' >
							<el-option v-for="(item, index) in fbbmOptions" :key="index" :label="item.F_FullName" :value="item.F_Id" ></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="发布日期" prop="fbrq"  >
						<el-date-picker v-model="dataForm.fbrq" placeholder="请选择" clearable :style='{"width":"100%"}' type="date" format="yyyy-MM-dd" value-format="timestamp" >
						</el-date-picker>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="是否现行" prop="sfxx"  >
						<el-select v-model="dataForm.sfxx" placeholder="请选择" clearable :style='{"width":"100%"}' >
							<el-option v-for="(item, index) in sfxxOptions" :key="index" :label="item.fullName" :value="item.id" ></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="启用日期" prop="qyrq"  >
						<el-date-picker v-model="dataForm.qyrq" placeholder="请选择" clearable :style='{"width":"100%"}' type="date" format="yyyy-MM-dd" value-format="timestamp" >
						</el-date-picker>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="适用部门" prop="sybm"  >
						<el-select filterable v-model="dataForm.sybm" placeholder="请选择" clearable :style='{"width":"100%"}' >
							<el-option v-for="(item, index) in sybmOptions" :key="index" :label="item.F_FullName" :value="item.F_Id" ></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="填写人部门" prop="txrbm"  >
						<el-select filterable v-model="dataForm.txrbm" @change="person" placeholder="请选择" clearable :style='{"width":"100%"}' >
							<el-option v-for="(item, index) in txrbmOptions" :key="index" :label="item.F_FullName" :value="item.F_Id" ></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="填写人" prop="txr"  >
						<!-- <el-select filterable v-model="dataForm.txr" placeholder="请选择" clearable :style='{"width":"100%"}' >
							<el-option v-for="(item, index) in txrOptions" :key="index" :label="item.F_RealName" :value="item.F_Id" ></el-option>
						</el-select> -->
						<el-select multiple v-model="dataForm.txr" placeholder="请先选择" clearable :style='{"width":"100%"}' filterable>
							<el-option v-for="(item, index) in personAll" :key="index" :label="item.realName" :value="item.id" ></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="分类" prop="axfl" >
						<el-select v-model="dataForm.axfl" placeholder="请选择" clearable :style='{"width":"100%"}' >
							<el-option v-for="(item, index) in axflOptions" :key="index" :label="item.fullName" :value="item.id" ></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="辨识评估记录文件" prop="zdxgfj" >
						<JNPF-UploadFz v-model="zdxgfjList" accept="" :fileSize="10" sizeUnit="MB" :limit="1" buttonText="点击上传" >
						</JNPF-UploadFz>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="辨识说明" prop="zy"  >
						<el-input v-model="dataForm.zy" placeholder="请输入" show-word-limit :style='{"width":"100%"}' type="textarea" :autosize='{"minRows":4,"maxRows":1000}' >
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="辨识评估" prop="sm"  >
						<el-input v-model="dataForm.sm" placeholder="请输入" show-word-limit :style='{"width":"100%"}' type="textarea" :autosize='{"minRows":4,"maxRows":1000}' >
						</el-input>
					</el-form-item>
				</el-col>
				<template>
					<div v-if="shContens">
						<el-col :span="12">
							<el-form-item label="评审日期" prop="psrq" >
								<el-date-picker v-model="dataForm.psrq" placeholder="请选择" clearable :style='{"width":"100%"}' type="date" format="yyyy-MM-dd" value-format="timestamp" >
								</el-date-picker>
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="评审人" prop="psr" >
								<el-select v-model="dataForm.psr" placeholder="请选择" clearable :style='{"width":"100%"}' >
									<el-option v-for="(item, index) in psrOptions" :key="index" :label="item.F_RealName" :value="item.F_Id" ></el-option>
								</el-select>
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="参评人员" prop="cpry" >
								<el-select v-model="dataForm.cpry" placeholder="请选择" clearable :style='{"width":"100%"}' >
									<el-option v-for="(item, index) in cpryOptions" :key="index" :label="item.F_RealName" :value="item.F_Id" ></el-option>
								</el-select>
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="评审相关附件" prop="psxgfj" >
								<JNPF-UploadFz v-model="psxgfjList" accept="" :fileSize="10" sizeUnit="MB" :limit="1" buttonText="点击上传" >
								</JNPF-UploadFz>
							</el-form-item>
						</el-col>
						<el-col :span="24">
							<el-form-item label="评审意见" prop="psyj" >
								<el-input v-model="dataForm.psyj" placeholder="请输入" show-word-limit :style='{"width":"100%"}' type="textarea" :autosize='{"minRows":4,"maxRows":1000}' >
								</el-input>
							</el-form-item>
						</el-col>
					</div>
				</template>
			</el-form>
			</el-row>
		</div>
	</transition>

</template>
<script>
import request from '@/utils/request'
import {getDictionaryDataSelector}from '@/api/systemData/dictionary'
import {previewDataInterface}from '@/api/systemData/dataInterface'
import {departmentPerson}from '@/api/systemIntegration/recard'

export default {
    data() {
      return {
				personAll:[], // 填写人
        visible: false,
        isDetail: false,
        dataForm: {
					aqzdmc:undefined,
					fbbm:undefined,
					fbrq:undefined,
					sfxx:undefined,
					qyrq:undefined,
					sybm:undefined,
					txr:undefined,
					txrbm:undefined,
					zdxgfj:[],
					zy:undefined,
					sm:undefined,
					psrq:undefined,
					psr:undefined,
					cpry:undefined,
					axfl:undefined,
					psxgfj:[],
					psyj:undefined,

        },
        rules: {
						aqzdmc:[
						{
							required:true,
							message:'请输入安全制度名称',
							trigger:'blur'
						},
						],
						fbbm:[
						{
							required:true,
							message:'请输入发布部门',
							trigger:'blur'
						},
						],
						fbrq:[
						{
							required:true,
							message:'请输入发布日期',
							trigger:'blur'
						},
						],
						sfxx:[
						{
							required:true,
							message:'请输入是否现行',
							trigger:'blur'
						},
						],
						qyrq:[
						{
							required:true,
							message:'请输入启用日期',
							trigger:'blur'
						},
						],
						sybm:[
						{
							required:true,
							message:'请输入适用部门',
							trigger:'blur'
						},
						],
						txr:[
						{
							required:true,
							message:'请输入填写人',
							trigger:'blur'
						},
						],
						txrbm:[
						{
							required:true,
							message:'请输入填写人部门',
							trigger:'blur'
						},
						],
						zy:[
						{
							required:true,
							message:'请输入辨识说明',
							trigger:'blur'
						},
						],
						sm:[
						{
							required:true,
							message:'请输入辨识评估',
							trigger:'blur'
						},
						],

        },
		fbbmOptions:[],
		sfxxOptions:[{"fullName":"是","id":"0"},{"fullName":"否","id":"1"}],
		axflOptions:[{"fullName":"法律法规","id":"法律法规"},{"fullName":"体系文件","id":"体系文件"},{"fullName":"规章制度","id":"规章制度"},{"fullName":"作业指导书","id":"作业指导书"}],
		sybmOptions:[],
		txrOptions:[],
		txrbmOptions:[],
		psrOptions:[],
		cpryOptions:[],

		zdxgfjList:[],
		psxgfjList:[],

		shContens: false

      }
    },
    created() {
		this.getfbbmOptions();
		this.getsybmOptions();
		this.gettxrOptions();
		this.gettxrbmOptions();
		this.getpsrOptions();
		this.getcpryOptions();

    },
    methods: {
		getfbbmOptions()
		{
			previewDataInterface('772d2cbcadd24df79243e3d92ef5f690').then(res => {
				this.fbbmOptions = res.data
			})
		},
		getsybmOptions()
		{
			previewDataInterface('772d2cbcadd24df79243e3d92ef5f690').then(res => {
				this.sybmOptions = res.data
			})
		},
		gettxrOptions()
		{
			previewDataInterface('8bca424f16d6448ab09e57a028853aa9').then(res => {
				this.txrOptions = res.data
			})
		},
		gettxrbmOptions()
		{
			previewDataInterface('772d2cbcadd24df79243e3d92ef5f690').then(res => {
				this.txrbmOptions = res.data
			})
		},
		getpsrOptions()
		{
			previewDataInterface('8bca424f16d6448ab09e57a028853aa9').then(res => {
				this.psrOptions = res.data
			})
		},
		getcpryOptions()
		{
			previewDataInterface('8bca424f16d6448ab09e57a028853aa9').then(res => {
				this.cpryOptions = res.data
			})
		},

        goBack() {
            this.$emit('refresh')
        },
      init(id, isDetail) {
		if(isDetail == true){
			this.shContens = true;
		}else{
			this.shContens = false;
		}
        this.dataForm.id = id || 0;
        this.visible = true;
        this.isDetail = isDetail || false;
        this.$nextTick(() => {
          this.$refs['elForm'].resetFields();
          if (this.dataForm.id) {
            request({
              url: '/api/System/qyscAqgzzd/' + this.dataForm.id,
              method: 'get'
            }).then(res =>{
              this.dataForm = res.data;
							this.zdxgfjList = this.dataForm.zdxgfj ? JSON.parse(this.dataForm.zdxgfj) : [];
							this.psxgfjList = this.dataForm.psxgfj ? JSON.parse(this.dataForm.psxgfj) : [];
            })
          }
        })
      },
			// 填写人
			async person(id) {
				this.dataForm.txr = ''
				const {data} = await departmentPerson({organizeId:id})
				this.personAll = data.list
			},
      // 表单提交
      dataFormSubmit() {
				this.$set(this.dataForm, 'zdxgfj', JSON.stringify(this.zdxgfjList));
				this.$set(this.dataForm, 'psxgfj', JSON.stringify(this.psxgfjList));

        this.$refs['elForm'].validate((valid) => {
          if (valid) {
            if (!this.dataForm.id) {
              request({
                url: '/api/System/qyscAqgzzd',
                method: 'post',
                data: this.dataForm,
              }).then((res) =>{
                this.$message({
                  message: res.msg,
                  type: 'success',
                  duration: 1000,
                  onClose: () =>{
                    this.visible = false;
                    this.$emit('refresh', true);
                  }
                })
              })
            } else {
              request({
                url: '/api/System/qyscAqgzzd/' + this.dataForm.id,
                method: 'PUT',
                data: this.dataForm
              }).then((res) =>{
                this.$message({
                  message: res.msg,
                  type: 'success',
                  duration: 1000,
                  onClose: () =>{
                    this.visible = false;
                    this.$emit('refresh', true);
                  }
                })
              })
            }
          }
        })
      },

    }
  }
  </script>